package cn.com.device.monitor.config;

import org.apache.iotdb.session.Session;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class IotdbConfig {

    @Value("${iotdb.host}")
    private String host;

    @Value("${iotdb.port}")
    private int port;

    @Value("${iotdb.username}")
    private String username;

    @Value("${iotdb.password}")
    private String password;

    @Bean
    public Session iotdbSession() {
        Session session = new Session(host, port, username, password);
        try {
            session.open(false);
        } catch (Exception e) {
            throw new RuntimeException("Failed to connect to IoTDB", e);
        }
        return session;
    }
}
